package com.shuangti.webdemo.controller;

import com.shuangti.webdemo.po.Dept;
import com.shuangti.webdemo.dto.DeptDto;
import com.shuangti.webdemo.po.Result;
import com.shuangti.webdemo.servvice.impl.DeptServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/depts")
@RestController
@RequiredArgsConstructor
public class DeptController {
    private final DeptServiceImpl deptService;
    /**
     * 部门列表的查询
     */

    @GetMapping
        public Result selectDept(){
        log.info("日志配置成功");
        log.info("日志配置成功");
        log.info("日志配置成功");
        log.info("日志配置成功");
        log.info("日志配置成功");
        log.info("日志配置成功");
        List<Dept> result = deptService.selectDeptList();

        return Result.success(result);

    }
    /**
     * 根据id删除部门
     *
     */
    @DeleteMapping
    public Result deleteDept(@RequestParam(value = "id" ,required = false) Integer id){
        deptService.DeleById(id);
        return Result.success();
    }

    /**
     * 添加部门
     */
    @PostMapping
    public Result addDept(@RequestBody DeptDto deptDto){

        deptService.addOne(deptDto);
        return Result.success();
    }

    /**
     * 根据id查询部门数据信息
     */
    @GetMapping("/{id}")
    public Result getDept(@PathVariable Integer id){
        Dept byId = deptService.getById(id);

        return Result.success(byId);
    }
}

